-- sage_skill1
-- created by wangy
-- 贤者之语（伤害）

return {
    -- 判断
    canTrigger = function(args)
        local chanceRange = args["chance"];
        if chanceRange and math.random(chanceRange[2]) > chanceRange[1] then
            -- 概率没触发
            return false;
        end
        return true;
    end,

    -- 触发
    trigger = function(args)
        -- 存活的怪物
        local targetPos;
        local aliveMonsters = AutoFightM.getData()["aliveMonsters"];
        if aliveMonsters and #aliveMonsters > 0 then
            targetPos = aliveMonsters[1];
        end

        local grid = DungeonM.getGridByPos(targetPos);

        -- 如果怪物已经死亡了
        if not grid.monster or grid.monster:isDead() then
            return false;
        end

        -- 先选择光系的圣语，被免疫了选择暗系
        local skillId = 92;
        if SkillM.immunitySkill(ME.user, grid.monster, skillId) then
            skillId = 93;
        end

        -- 对敌方施法
        if targetPos and DungeonActionM.go("stone_skill", targetPos, nil, skillId) then
            return true;
        end
        return false;
    end,
};
